﻿#region Using References

using System.IO;
using Beaker.OpenCube.NbtEditor.Messages;
using Beaker.OpenCube.NbtEditor.ViewModels;
using GalaSoft.MvvmLight.Messaging;
using Microsoft.Win32;

#endregion

namespace Beaker.OpenCube.NbtEditor
{
	/// <summary>
	/// Interaction logic for MainWindow.xaml
	/// </summary>
	public partial class MainWindow
	{
		public MainWindow()
		{
			InitializeComponent();
			Messenger.Default.Register<ShowViewMessage>( this, OnShowViewMessage );
		}

		private void OnShowViewMessage( ShowViewMessage message )
		{
			// some special cases, like build in dialogs
			var fileSelectedViewModel = message.ViewModel as FileSelectorViewModel;
			if( fileSelectedViewModel != null )
			{
				var dialog = new OpenFileDialog();
				dialog.Multiselect = false;
				dialog.InitialDirectory = fileSelectedViewModel.ActivePath; 
				bool? result = dialog.ShowDialog();

				if( result == true )
				{
					fileSelectedViewModel.ActivePath = Path.GetDirectoryName( dialog.FileName );
					fileSelectedViewModel.ResultPath = dialog.FileName;
				}


				message.SendResultAvailable();
			}

			// all other viewmodels
		}
	}
}
